package com.yidu.DailyFinalTreatment.controller;

import com.yidu.BusinessParameters.entity.CashAccruedEntity;
import com.yidu.BusinessParameters.service.CashAccruedEntityService;
import com.yidu.DailyFinalTreatment.entity.BondSecurity;
import com.yidu.DailyFinalTreatment.entity.CashInventMo;
import com.yidu.DailyFinalTreatment.service.CashInventMoService;


import com.yidu.Util.util.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class CashInventMoController {
    @Resource
    private CashInventMoService cashInventService;
    @Resource
    private CashAccruedEntityService accruedEntityService;
    @Resource
    private Dbutil dbUtil;

    @RequestMapping("cashInventSelect")
    public Map cashInventSelec(String date){
        System.out.println("123");
        List<CashInventMo> cashInventMos = cashInventService.selectCashinvent(date);
        Map map =new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("data",cashInventMos);
        System.out.println("cashInventMos"+cashInventMos);
        System.out.println("map"+map.get("data"));
        System.out.println("date="+date);
        return map;

    }

    //现金利息统计
    @RequestMapping("CountingCash")
    public int CountingCash(String cash) {
        int i=0;
        System.out.println("进来了===============================================");
        System.out.println(cash);
        List<CashInventMo> cashInventMoList = SysUtil.jsonToArrayList(cash,CashInventMo.class);
        System.out.println("bondSecurityList="+cashInventMoList);
        CashAccruedEntity cashAccruedEntity =new CashAccruedEntity();
        for (CashInventMo cashInventMo:cashInventMoList){
            //setCashDate放入时间
            cashAccruedEntity.setCashDate(cashInventMo.getCashInventorysTime());
            //setFundId放入基金id
            cashAccruedEntity.setFundId(cashInventMo.getFundId());
            cashAccruedEntity.setCashId(cashInventMo.getCashId());
            String cashAccruedId= dbUtil.getMaxId3(TableIdUtil.CAID, TableNameUtil.CA, TableTimeUtil.CATime,cashAccruedEntity.getCashDate());
            cashAccruedEntity.setCashAccruedId(cashAccruedId);
            cashAccruedEntity.setBusinessType(3);
            cashAccruedEntity.setMoneySun(cashInventMo.getInterest());
            System.out.println("利息金额="+cashInventMo.getInterest());
            cashAccruedEntity.setMoneyFlow(1);
            i = accruedEntityService.cashInventoryinsert(cashAccruedEntity);
            if (i>0){
                i=accruedEntityService.cashDeleteNew(cashAccruedEntity);
                if (i>0){
                    i=accruedEntityService.cashInventoryinsert(cashAccruedEntity);
                    System.out.println("这是现金应收应付先删后增的i"+i);
                    System.out.println("syt");
                }
            }
        }
        return i;
    }

}
